import mx.events.*;
import mx.managers.DragManager;
import mx.core.DragSource;
import mx.controls.Alert;

private var dragOffsetX: int;
private var dragOffsetY: int;

public function initStack(data: Array): void {
    lstStack.dataProvider = data;
    lstStack.dataProvider.addEventListener("collectionChange", handleListChange);
    tiName.setFocus();
    tiName.text = "enter stack name";
    tiName.setSelection(0, tiName.text.length);
}

private function saveStackName(): void {
    tiName.visible = false;
    tiName.includeInLayout = false;
    lblName.text = tiName.text;
    lblName.visible = true;
    lblName.includeInLayout = true;
}

public function getSelectedIssue(): Object {
    return lstStack.selectedItem;
}

private function handleMouseMove(event: MouseEvent): void {
    dragOffsetX = event.localX;
    dragOffsetY = event.localY;
    var dragInitiator: IssueStack = event.currentTarget.parent as IssueStack;
    var ds: DragSource = new DragSource();
    ds.addData(dragInitiator, "issueStack");
    var labelProxy: Label = new Label();
    labelProxy.text = lblName.text;
    DragManager.doDrag(dragInitiator, ds, event, labelProxy);
}

private function handleListChange(event: CollectionEvent): void {
    if (lstStack.dataProvider.length == 0) {
        parent.removeChild(this);
    }
}

public function getDragOffsetX(): int {
    return dragOffsetX;
}

public function getDragOffsetY(): int {
    return dragOffsetY;
}
